/*
 *  Class name: BookDAOImpl.java
 *  Version: 1.0
 *  Date: 22.6.2014
 */

package cz.morosystems.personwebmanager.persistencelayer.daos.impl;

import cz.morosystems.personwebmanager.persistencelayer.daos.BookDAO;
import cz.morosystems.personwebmanager.persistencelayer.entities.Book;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 *
 * @author Michal Ďuriš
 */
@Repository
public class BookDAOImpl implements BookDAO {

    @Autowired
    private SessionFactory sessionFactory;
    
    public BookDAOImpl() {
    }

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    @Override
    public void changeBook(Book book) {
        sessionFactory.getCurrentSession().merge(book);
    }

    @Override
    public void deleteBook(Long bookID) {
        sessionFactory.getCurrentSession().delete(getBookByID(bookID));
    }

    @Override
    public Book getBookByID(Long bookID) {
        
        return (Book) sessionFactory.getCurrentSession().get(Book.class, bookID);
    }
    
}
